'''
Created on 03/12/2012

@author: Andres
'''
import numpy as np
import nipype.interfaces.io as nio
import nipype.interfaces.fsl as fsl
import nipype.interfaces.spm as spm
import nipype.interfaces.utility as util
import nipype.pipeline.engine as pe
import nipype.algorithms.modelgen as model
import os
import nipype.pipeline.plugins

fsl.FSLCommand.set_default_output_type('NIFTI')
data = './Inputs'
os.chdir(data)
data_dir = os.path.abspath('.')
subject_list = ['Sub_1','Sub_2']

datasource=pe.Node(interface=nio.DataGrabber(infields=['subject_id'], outfields=['func', 'struct']), name='datasource')
datasource.inputs.base_directory=data_dir
datasource.inputs.template='%s/%s'
datasource.inputs.field_template = dict(func=('%s/BOLD/%s_BOLD.nii'),struct=('%s/T1/o_%s_T1.nii'))
datasource.inputs.template_args = dict(func=[['subject_id', 'subject_id']],struct=[['subject_id', 'subject_id']])
datasource.iterables = ('subject_id', subject_list)

#structural processing
extract_ref = pe.Node(interface=fsl.ExtractROI(t_min=42, t_size=1), name='extractref')

#nosestrip = pe.Node(interface=fsl.BET(frac=3.0), name='nosestrip')
skullstrip = pe.Node(interface=fsl.BET(mask = True), name='stripstruct')
refskullstrip = pe.Node(interface=fsl.BET(mask = True), name = 'stripref')
coregister = pe.Node(interface=fsl.FLIRT(dof=6), name = 'coregister')


#Functional processing
motion_correct = pe.Node(interface=fsl.MCFLIRT(save_plots = True), name = 'realign')
func_skullstrip = pe.Node(interface=fsl.BET(functional = True), name='stripfunc')
smoother= pe.Node(interface=spm.Smooth(), name='smooth')
smoother.iterables=('fwhm', [0,3,6])
